﻿using HandyControl.Controls;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BaseUi.Views.PlcView
{
    /// <summary>
    /// OutinformationView.xaml 的交互逻辑
    /// </summary>
    public partial class OutinformationView : UserControlBase
    {
        private informationData viewformModel = new informationData();
        public SolidColorBrush RedColor = new SolidColorBrush(Color.FromRgb(255, 69, 0));
        public SolidColorBrush GreenColor = new SolidColorBrush(Color.FromRgb(173, 255, 47));
        public SolidColorBrush BoroColor = new SolidColorBrush(Color.FromRgb(220, 220, 220));
        public OutinformationView()
        {
            InitializeComponent();
            DataContext = viewformModel;
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            Task informnat = new Task(() =>
            {
                while (true)
                {
                    getinform();
                    Thread.Sleep(200);
                }
            });
            informnat.Start();
        }

        private void getinform()
        {
            var ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 00).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g1 = BoroColor;
                viewformModel.outlabel1g1 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g1 = GreenColor;
                    viewformModel.outlabel1g1 = "ON";
                }
                else
                {
                    viewformModel.outborder1g1 = RedColor;
                    viewformModel.outlabel1g1 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 01).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g2 = BoroColor;
                viewformModel.outlabel1g2 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g2 = GreenColor;
                    viewformModel.outlabel1g2 = "ON";
                }
                else
                {
                    viewformModel.outborder1g2 = RedColor;
                    viewformModel.outlabel1g2 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 02).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g3 = BoroColor;
                viewformModel.outlabel1g3 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g3 = GreenColor;
                    viewformModel.outlabel1g3 = "ON";
                }
                else
                {
                    viewformModel.outborder1g3 = RedColor;
                    viewformModel.outlabel1g3 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 03).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g4 = BoroColor;
                viewformModel.outlabel1g4 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g4 = GreenColor;
                    viewformModel.outlabel1g4 = "ON";
                }
                else
                {
                    viewformModel.outborder1g4 = RedColor;
                    viewformModel.outlabel1g4 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 04).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g5 = BoroColor;
                viewformModel.outlabel1g5 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g5 = GreenColor;
                    viewformModel.outlabel1g5 = "ON";
                }
                else
                {
                    viewformModel.outborder1g5 = RedColor;
                    viewformModel.outlabel1g5 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 05).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g6 = BoroColor;
                viewformModel.outlabel1g6 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g6 = GreenColor;
                    viewformModel.outlabel1g6 = "ON";
                }
                else
                {
                    viewformModel.outborder1g6 = RedColor;
                    viewformModel.outlabel1g6 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 06).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g7 = BoroColor;
                viewformModel.outlabel1g7 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g7 = GreenColor;
                    viewformModel.outlabel1g7 = "ON";
                }
                else
                {
                    viewformModel.outborder1g7 = RedColor;
                    viewformModel.outlabel1g7 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 07).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outborder1g8 = BoroColor;
                viewformModel.outlabel1g8 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outborder1g8 = GreenColor;
                    viewformModel.outlabel1g8 = "ON";
                }
                else
                {
                    viewformModel.outborder1g8 = RedColor;
                    viewformModel.outlabel1g8 = "OFF";
                }
            }

            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 08).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform1g9 = BoroColor;
                viewformModel.Contoutinform1g9 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform1g9 = GreenColor;
                    viewformModel.Contoutinform1g9 = "ON";
                }
                else
                {
                    viewformModel.outinform1g9 = RedColor;
                    viewformModel.Contoutinform1g9 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 09).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform1g10 = BoroColor;
                viewformModel.Contoutinform1g10 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform1g10 = GreenColor;
                    viewformModel.Contoutinform1g10 = "ON";
                }
                else
                {
                    viewformModel.outinform1g10 = RedColor;
                    viewformModel.Contoutinform1g10 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 10).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g1 = BoroColor;
                viewformModel.Contoutinform2g1 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g1 = GreenColor;
                    viewformModel.Contoutinform2g1 = "ON";
                }
                else
                {
                    viewformModel.outinform2g1 = RedColor;
                    viewformModel.Contoutinform2g1 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 11).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g2 = BoroColor;
                viewformModel.Contoutinform2g2 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g2 = GreenColor;
                    viewformModel.Contoutinform2g2 = "ON";
                }
                else
                {
                    viewformModel.outinform2g2 = RedColor;
                    viewformModel.Contoutinform2g2 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 12).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g3 = BoroColor;
                viewformModel.Contoutinform2g3 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g3 = GreenColor;
                    viewformModel.Contoutinform2g3 = "ON";
                }
                else
                {
                    viewformModel.outinform2g3 = RedColor;
                    viewformModel.Contoutinform2g3 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 13).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g4 = BoroColor;
                viewformModel.Contoutinform2g4 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g4 = GreenColor;
                    viewformModel.Contoutinform2g4 = "ON";
                }
                else
                {
                    viewformModel.outinform2g4 = RedColor;
                    viewformModel.Contoutinform2g4 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 14).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g5 = BoroColor;
                viewformModel.Contoutinform2g5 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g5 = GreenColor;
                    viewformModel.Contoutinform2g5 = "ON";
                }
                else
                {
                    viewformModel.outinform2g5 = RedColor;
                    viewformModel.Contoutinform2g5 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 15).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g6 = BoroColor;
                viewformModel.Contoutinform2g6 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g6 = GreenColor;
                    viewformModel.Contoutinform2g6 = "ON";
                }
                else
                {
                    viewformModel.outinform2g6 = RedColor;
                    viewformModel.Contoutinform2g6 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 16).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g7 = BoroColor;
                viewformModel.Contoutinform2g7 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g7 = GreenColor;
                    viewformModel.Contoutinform2g7 = "ON";
                }
                else
                {
                    viewformModel.outinform2g7 = RedColor;
                    viewformModel.Contoutinform2g7 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 17).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g8 = BoroColor;
                viewformModel.Contoutinform2g8 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g8 = GreenColor;
                    viewformModel.Contoutinform2g8 = "ON";
                }
                else
                {
                    viewformModel.outinform2g8 = RedColor;
                    viewformModel.Contoutinform2g8 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 18).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g9 = BoroColor;
                viewformModel.Contoutinform2g9 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g9 = GreenColor;
                    viewformModel.Contoutinform2g9 = "ON";
                }
                else
                {
                    viewformModel.outinform2g9 = RedColor;
                    viewformModel.Contoutinform2g9 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 19).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g10 = BoroColor;
                viewformModel.Contoutinform2g10 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g10 = GreenColor;
                    viewformModel.Contoutinform2g10 = "ON";
                }
                else
                {
                    viewformModel.outinform2g10 = RedColor;
                    viewformModel.Contoutinform2g10 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 20).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform2g11 = BoroColor;
                viewformModel.Contoutinform2g11 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform2g11 = GreenColor;
                    viewformModel.Contoutinform2g11 = "ON";
                }
                else
                {
                    viewformModel.outinform2g11 = RedColor;
                    viewformModel.Contoutinform2g11 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 21).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform3g1 = BoroColor;
                viewformModel.Contoutinform3g1 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform3g1 = GreenColor;
                    viewformModel.Contoutinform3g1 = "ON";
                }
                else
                {
                    viewformModel.outinform3g1 = RedColor;
                    viewformModel.Contoutinform3g1 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 30).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform3g2 = BoroColor;
                viewformModel.Contoutinform3g2 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform3g2 = GreenColor;
                    viewformModel.Contoutinform3g2 = "ON";
                }
                else
                {
                    viewformModel.outinform3g2 = RedColor;
                    viewformModel.Contoutinform3g2 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 31).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.outinform3g3 = BoroColor;
                viewformModel.Contoutinform3g3 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.outinform3g3 = GreenColor;
                    viewformModel.Contoutinform3g3 = "ON";
                }
                else
                {
                    viewformModel.outinform3g3 = RedColor;
                    viewformModel.Contoutinform3g3 = "OFF";
                }
            }
        }

        
        private void outinformButton_Click1g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("300", (sender as Button).Content=="OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("301", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g1z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("302", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("303", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("304", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }

        }

        private void outinformButton_Click2g4z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("305", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g5z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("306", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g6z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("307", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g7z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("308", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g8z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("309", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g9z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("310", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g10z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("311", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g11z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("312", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click3g1z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("313", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click3g2z1(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("314", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("315", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click3g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("315", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
    }
}
